package com.acargil.sudoku.view;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import com.acargil.sudoku.view.listeners.AboutListener;
import com.acargil.sudoku.view.listeners.ClearListener;
import com.acargil.sudoku.view.listeners.ExitListener;
import com.acargil.sudoku.view.listeners.GenerateListener;
import com.acargil.sudoku.view.listeners.LoadListener;
import com.acargil.sudoku.view.listeners.SaveListener;
import com.acargil.sudoku.view.listeners.SolveListener;

public class MenuBar extends JMenuBar {

	private static final long serialVersionUID = -6994218537068339480L;

	private SaveListener saveListener;
	private LoadListener loadListener;
	private ClearListener clearListener;
	private ExitListener exitListener;
	private AboutListener aboutListener;
	private SolveListener solveListener;
	private GenerateListener generateListener;
	
	public MenuBar( ) {
		init();
	}

	private void init() {
		JMenu fileMenu, gameMenu, aboutMenu;
		JMenu solveMenu, generateMenu;
		JMenuItem saveItem, loadItem, exitItem, cleanItem, aboutItem;
		JMenuItem basicSolve, basicGenerate;
		
		// Menus
		fileMenu = new JMenu("File");
		gameMenu = new JMenu("Game");
		aboutMenu = new JMenu("About");

		// Sub-menus
		solveMenu = new JMenu("Solve");
		generateMenu = new JMenu("Generate");
		
		// Menu items
		saveItem = new JMenuItem("Save Game");
		saveItem.addActionListener(saveListener);
		loadItem = new JMenuItem("Load Game");
		loadItem.addActionListener(loadListener);
		exitItem = new JMenuItem("Exit");
		exitItem.addActionListener(exitListener);
		cleanItem = new JMenuItem("Clean");
		cleanItem.addActionListener(clearListener);
		aboutItem = new JMenuItem("About");
		aboutItem.addActionListener(aboutListener);
		basicSolve = new JMenuItem("Basic Solve");
		basicSolve.addActionListener(solveListener);
		basicGenerate = new JMenuItem("Basic Generate");
		basicGenerate.addActionListener(generateListener);
		
		fileMenu.add(saveItem);
		fileMenu.add(loadItem);
		fileMenu.addSeparator();
		fileMenu.add(exitItem);
		
		// TODO add new solving & generating algorithms
		solveMenu.add(basicSolve);
		generateMenu.add(basicGenerate);
		
		gameMenu.add(solveMenu);
		gameMenu.add(generateMenu);
		gameMenu.addSeparator();
		gameMenu.add(cleanItem);
		
		aboutMenu.add(aboutItem);
		
		this.add(fileMenu);
		this.add(gameMenu);
		this.add(aboutMenu);
	}
	
}
